package com.qf.service.impl;

import com.qf.Excaption.MyExcaption;
import com.qf.domain.Answers;
import com.qf.domain.Questions;
import com.qf.mapper.AnswersMapper;
import com.qf.service.AnswersService;
import com.qf.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AnswersServiceimpl implements AnswersService {
    @Autowired
    private AnswersMapper answersMapper;
    @Autowired
    private QuestionsService questionsService;
    @Transactional
    @Override
    public int insertAnswers(Answers answers) {
        if (answers==null){
            throw new MyExcaption("无法获取道数据",500);
        }else {
            int i=answersMapper.insertAnswers(answers);
            int q=questionsService.update(answers.getQid());
            if (i!=1&&q==i){
                throw new MyExcaption("无法获取道数据",500);
            }else {
                return i;
            }
        }



    }
}
